//
//  MovieCell.m
//  Project1
//
//  Created by 黄珂耀 on 15/7/20.
//  Copyright (c) 2015年 黄珂耀. All rights reserved.
//

#import "MovieCell.h"
#import "UIImageView+WebCache.h"
#import "StarView.h"

@implementation MovieCell

- (void)awakeFromNib {
    // Initialization code
    
    self.selectionStyle = UITableViewCellSelectionStyleDefault;

}

- (void)setModal:(MovieModal *)modal
{
    _modal = modal;
    [self setNeedsLayout];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_main"]];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    _titleLabel.text = _modal.title;
    _titleLabel.textColor = [UIColor orangeColor];
    
    [self setStar];
    
    NSString *yearStr = [NSString stringWithFormat:@"年份:%@",_modal.year];
    _yearLabel.text = yearStr;
    _yearLabel.font = [UIFont systemFontOfSize:14];
    _yearLabel.textColor = [UIColor whiteColor];
    _averageLabel.text = [NSString stringWithFormat:@"%.1f",_modal.average];
    _averageLabel.textColor = [UIColor whiteColor];
    
    NSString *imageURl = [_modal.images objectForKey:@"large"];
    [_iconImageView sd_setImageWithURL:[NSURL URLWithString:imageURl]];

}

- (void)setStar
{
//    UIImage *gray = [UIImage imageNamed:@"gray"];
//    UIImage *yellow = [UIImage imageNamed:@"yellow"];
//    
//    float k;
//    k = _modal.average / 10;
//    //    NSLog(@"%f",k);
//    
//    UIView *grayView = [[UIView alloc] initWithFrame:CGRectMake(100, 35, gray.size.width * 5, gray.size.height)];
//    [grayView setBackgroundColor:[UIColor colorWithPatternImage:gray]];
//    
//    UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(100, 35, yellow.size.width * 5 * k, yellow.size.height)];
//    [yellowView setBackgroundColor:[UIColor colorWithPatternImage:yellow]];
//    
//    [self addSubview:grayView];
//    [self addSubview:yellowView];
    
    StarView *starView = [[StarView alloc] initWithFrame:CGRectMake(100, 34, 175, 20)];
    starView.average = _modal.average;
    [self addSubview:starView];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
